package MyRemoteSorter;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class BubbleSort extends UnicastRemoteObject implements ISorter 
{
	public BubbleSort() throws RemoteException
	{
		super();
	}
	public Comparable[] sort(Comparable[] comparable)
	{
		if (comparable == null)
			throw new IllegalArgumentException("De array is leeg.");
		else {
		    boolean changed = false;
		    do {
		        for (int index = 0; index < comparable.length - 1; index++) {
		            if (comparable[index].compareTo(comparable[index + 1]) > 0) {
		                Comparable temp = comparable[index];
		                comparable[index] = comparable[index + 1];
		                comparable[index + 1] = temp;
		                changed = true;
		            }
		        }
		    } while (changed);
		}
		return comparable;

	}
}
